package com.blog.service.impl;

import com.blog.mapper.AdminMapper;
import com.blog.pojo.AdminInfoVO;
import com.blog.pojo.PageBean;
import com.blog.service.AdminService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public void insertAdmin(int id) {
        String identity = "普通管理员";
        adminMapper.insertAdmin(id, identity);
    }

    @Override
    public void deleteAdmin(int id) {
        adminMapper.deleteAdmin(id);
    }

    @Override
    public PageBean listAdmins(Integer page, Integer pageSize) {
        // 设置分页参数
        PageHelper.startPage(page, pageSize);
        // 执行分页查询
        List<AdminInfoVO> adminList = adminMapper.listAdmins();
        // 获取分页结果
        Page<AdminInfoVO> p = (Page<AdminInfoVO>) (adminList);
        // 封装PageBean
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
